
package com.stnet.web.enterprice.system;

import java.net.URLDecoder;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.security.providers.encoding.Md5PasswordEncoder;

import com.opensymphony.xwork2.ActionContext;
import com.stnet.bases.BaseAction;
import com.stnet.entity.Users;

public class CheckMemberAction extends BaseAction {

	public CheckMemberAction() {
	}

	public String checkName() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String name = request.getParameter("loginName");
		String orgName = request.getParameter("orgName");
		name = URLDecoder.decode(name, "UTF-8");
		orgName = URLDecoder.decode(orgName, "UTF-8");
		if (usersManagerDao.isNameUnique(name, orgName))
			return renderText("true");
		else
			return renderText("false");
	}
	
	public String checkPwd() throws Exception {
		
		HttpServletRequest request = ServletActionContext.getRequest();
		String passwordTemp = request.getParameter("oldPassword");

		Map session = (Map) ActionContext.getContext().getSession();
		Users users = (Users)session.get("member");
		
		String password = (new Md5PasswordEncoder()).encodePassword(passwordTemp,
				users.getLoginName());
		
		if (users != null && users.getPassword().equalsIgnoreCase(password)) {
			return renderText("true");
		} else {
			this.addActionMessage("旧密码不正确.");
			return renderText("false");
		}
	}

	private static final long serialVersionUID = 0xe1bca1fd8ed0ad1dL;
}